package com.hnucm.c201901020241;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;

import com.chaychan.library.BottomBarLayout;
import com.hnucm.c201901020241.fragment.DisscussFragment;
import com.hnucm.c201901020241.fragment.DongtaiFragment;
import com.hnucm.c201901020241.fragment.HomeFragment;
import com.hnucm.c201901020241.fragment.MyFragment;
import com.hnucm.c201901020241.utils.DepthPageTransformer;


import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity{
    ViewPager mViewPager;
    BottomBarLayout mBottomBarLayout;
    List<Fragment> pagelists;//所有fragment
    FragmentAdapter fragmentAdapter;
    public static final String action = "lead";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mBottomBarLayout=findViewById(R.id.bbl);
        mViewPager=findViewById(R.id.vp_content);
        mBottomBarLayout.setSmoothScroll(true);//开启滑动效果
        init_data();//初始化
//        mViewPager.setPageTransformer(true, new DepthPageTransformer());

    }


    private void init_data(){
        pagelists=new ArrayList<>();
        pagelists.add(new HomeFragment());
        pagelists.add(new DisscussFragment());
        pagelists.add(new DongtaiFragment());
        pagelists.add(new MyFragment());
        fragmentAdapter=new FragmentAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(fragmentAdapter);
        mBottomBarLayout.setViewPager(mViewPager);
        SharedPreferences sharedPreferences=getSharedPreferences("user",MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("init1",false);
        editor.putBoolean("init2",false);
        editor.putBoolean("init3",false);
        editor.putBoolean("init4",false);
    }

    public class FragmentAdapter extends FragmentPagerAdapter {
        private Fragment mCurrentFragment;


        public FragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return pagelists.get(position);
        }


        @Override
        public int getCount() {
            return pagelists.size();
        }

        public Fragment getCurrentFragment() {
            return mCurrentFragment;
        }
    }
}
